package com.jic.interaction.clearAndSettlementSystem.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jic.common.base.vo.RestResult;
import com.jic.interaction.clearAndSettlementSystem.model.vo.request.CommercialTenantMsgSyncRequest;
import com.jic.interaction.clearAndSettlementSystem.model.vo.request.LiquidationResultDetailSyncRequest;
import com.jic.interaction.clearAndSettlementSystem.model.vo.request.OrderSyncRequest;
import com.jic.interaction.clearAndSettlementSystem.model.vo.request.SettlementIntervalSyncRequset;
import com.jic.interaction.clearAndSettlementSystem.service.ClearAndSettlementSystemService;
import com.jic.weamop.api.WeAMOPApi;
import com.jic.weamop.request.ChannelResponseApi;
import com.jic.weamop.request.MessageRequestApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class ClearAndSettlementSystemServiceImpl implements ClearAndSettlementSystemService {

    @Resource
    WeAMOPApi weAMOPApi;
    @Override
    public com.jic.common.base.vo.RestResult<ChannelResponseApi> commercialTenantMsgSync(CommercialTenantMsgSyncRequest request) {
        log.info("查询商户信息同步，入参 = {}", JSON.toJSONString(request));
        String topic="WEBANK_BCCES_MALL";
        String param = JSONObject.toJSONString(request);
        Map map = JSONObject.parseObject(param,Map.class);
        Map m = new HashMap();
        m.put("value",map);
        m.put("msgType",request.getMsgType());
        log.info("查询订单同步信息，入参 = {}", JSON.toJSONString(m));
        MessageRequestApi messageRequestApi = new MessageRequestApi();
        messageRequestApi.setToTopic(topic);
        messageRequestApi.setServiceId("10001");
        messageRequestApi.setMessage(JSON.toJSONString(m));
        log.info("查询商户信息同步，出参 = {}", JSON.toJSONString(messageRequestApi));
        return weAMOPApi.sendMessage(messageRequestApi);
    }

    @Override
    public com.jic.common.base.vo.RestResult<ChannelResponseApi> settlementIntervalSync(SettlementIntervalSyncRequset request) {
        log.info("查询结算周期同步信息，入参 = {}", JSON.toJSONString(request));
        String topic="WEBANK_BCCES_MALL";
        Map map;
        map = new HashMap();
        map.put("supplierId",request.getSupplierId());
        map.put("purchaserId",request.getPurchaserId());
        map.put("clearInterval",request.getClearInterval());
        map.put("clearCycle",request.getClearCycle());
        map.put("autoPayment",request.getAutoPayment());

        Map m = new HashMap();
        m.put("value",JSON.toJSONString(map));
        m.put("msgType",request.getMsgType());

        MessageRequestApi messageRequestApi = new MessageRequestApi();
        messageRequestApi.setToTopic(topic);
        messageRequestApi.setServiceId("10001");
        messageRequestApi.setMessage(JSON.toJSONString(m));
        log.info("查询结算周期同步，出参 = {}", JSON.toJSONString(messageRequestApi));
        return weAMOPApi.sendMessage(messageRequestApi);
    }

    @Override
    public com.jic.common.base.vo.RestResult<ChannelResponseApi> orderSync(OrderSyncRequest request) {
        String topic="WEBANK_BCCES_MALL";
        String param = JSONObject.toJSONString(request);
        Map map = JSONObject.parseObject(param,Map.class);
        Map m = new HashMap();
        m.put("value",map);
        m.put("msgType",request.getMsgType());
        log.info("查询订单同步信息，入参 = {}", JSON.toJSONString(m));
        MessageRequestApi messageRequestApi = new MessageRequestApi();
        messageRequestApi.setToTopic(topic);
        messageRequestApi.setServiceId("10001");
        messageRequestApi.setMessage(JSON.toJSONString(m));
        log.info("查询订单同步，出参 = {}", JSON.toJSONString(messageRequestApi));
        return weAMOPApi.sendMessage(messageRequestApi);
    }

    @Override
    public RestResult<ChannelResponseApi> liqudationResultDetailSync(LiquidationResultDetailSyncRequest request) {
        log.info("查询结算周期同步信息，入参 = {}", JSON.toJSONString(request));
        String topic="WEBANK_BCCES_CLS_FEC99782EB3861A194549F95A90580C6";
        MessageRequestApi messageRequestApi = new MessageRequestApi();
        messageRequestApi.setToTopic(topic);
        messageRequestApi.setServiceId("10001");
        messageRequestApi.setMessage(JSON.toJSONString(request));
        log.info("查询清算结果明细同步，出参 = {}", JSON.toJSONString(messageRequestApi));
        return weAMOPApi.sendMessage(messageRequestApi);
    }
}
